package com.t.bricks.bussiness.controller.lucene;

import io.swagger.annotations.Api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.service.lucene.LuceneCoreService;
import com.t.bricks.model.MsgEmity;
import com.t.bricks.model.Page;

@RestController
@Api(value="搜索引擎", tags={"系统附属-搜索引擎操作接口"})
@RequestMapping("/lucene/")
public class LuceneCoreController {

	/**
	 * 搜索引擎文件主路径
	 */
	@Autowired
	private LuceneCoreService luceneCoreService;

	/**
	 * 查询数据
	 * @param field
	 * @param key
	 * @param page
	 * @param coreName 库名,默认要求跟表名一致
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST}, value="/inside/core/search")
	public MsgEmity search(String field, String key, Page page, String coreName) {
		return luceneCoreService.search(field, key, null, page, coreName);
	}

	/**
	 * 删除索引库
	 * @param coreName 库名,默认要求跟表名一致
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST}, value="/inside/core/del")
	public MsgEmity del(String coreName) {
		return luceneCoreService.del(coreName);
	}

	/**
	 * 删除索引库
	 * @param coreName 库名,默认要求跟表名一致
	 * @return
	 */
	@RequestMapping(method={RequestMethod.POST}, value="/inside/core/rebuild")
	public MsgEmity rebuild(String coreName) {
		return luceneCoreService.rebuild(coreName);
	}

}
